<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src=""></script>
    <title>Vue</title>
</head>

<body>

    <input type="text" id="textInput"> 输入：
    <span id="textSpan"></span>


    <script>
        (function() {
            var obj = {},
                textInput = document.querySelector("#textInput"),
                textSpan = document.querySelector("#textSpan")
            Object.defineProperty(obj, 'foo', {
                get: function() {
                    console.log("将要读取foo值")
                },
                set: function(newValue) {
                    textInput.value = newValue
                    textSpan.innerHTML = newValue
                }
            });

            textInput.addEventListener('keyup', function(e) {
                console.log("keyUp")
                obj.foo = e.target.value
            })

        })();

        //
        (function() {
            var obj1 = {}
            var textInput = document.querySelector("#textInput")
            var textSpan = document.querySelector("#textSpan")
            Object.defineProperty(obj1, 'foo', {
                set: function(newValue) {
                    textInput.value = newValue
                    textSpan.innerHTML = newValue
                }
            })

            textInput.addEventListener('keyup', function(e) {
                obj1.foo = e.target.value
            })
        })();
    </script>

    <br>

    <span>输入：</span>
    <span id="spanid"></span>
    <input type="text" id="inputid">

    <script>
        (function() {
            var obj = {}
            var input = document.getElementById("inputid")
            var span = document.getElementById("spanid")
            Object.defineProperty(obj, 'foo', {
                set: function(newValue) {
                    input.value = newValue
                    span.innerHTML = newValue
                }
            });

            input.addEventListener('keyup', function(event) {
                obj.foo = event.target.value
            });
        })();
    </script>




</body>

</html>